home *** CD-ROM | disk | FTP | other *** search
/ Plug-In Power Pack for Netscape Communicator / Plug-In Power Pack for Netscape Communicator.iso / plugins / dataviews / dvtools / examples / fds / fdsrandom / fdsrandom.c
Encoding:
C/C++ Source or Header  |  1997-05-08  |  5.6 KB  |  209 lines

  1. /*
  2. |    file name -- FDSRandom.c
  3. |===================================================================
  4. |
  5. | Example for Function DataSource Function Descriptors.
  6. |
  7. |    InitRandom() init function - has one argument, the seed
  8. |    ReadRandom() read function - does nothing
  9. |    TermRandom() term function - does nothing
  10. |    SelectRandom() select function - has two arguments specifying
  11. |                   the range of the data
  12. |
  13. |===================================================================
  14. */
  15.  
  16. #ifndef lint
  17. static char *SccsId = "@(#)FDSrandom.c    V1.25    3/13/95";
  18. #endif
  19.  
  20. #include "std.h"
  21. #include "dvfds.h"
  22. #include "dvtools.h"
  23. #include "Tfundecl.h"
  24. #include "VUfundecl.h"
  25.  
  26. /***************** Begin Function Declarations *************/
  27. LOCAL  LONG InitRandom V_P_((LONG seed));
  28. LOCAL  LONG ReadRandom V_P_((void));
  29. LOCAL  LONG TermRandom V_P_((void));
  30. LOCAL  LONG CharSelectRandom V_P_((double *minval, double *maxval));
  31. LOCAL  LONG ShortSelectRandom V_P_((double *minval, double *maxval));
  32. LOCAL  LONG LongSelectRandom V_P_((double *minval, double *maxval));
  33. LOCAL  LONG FloatSelectRandom V_P_((double *minval, double *maxval));
  34. LOCAL  LONG DoubleSelectRandom V_P_((double *minval, double *maxval));
  35. LOCAL  LONG MatrixSelectRandom V_P_((double *minval, double *maxval));
  36. /***************** End Function Declarations *************/
  37.  
  38. /* This module uses two external routines, VUsrand() and VUfrand(),
  39.    which compose random number genertor module.
  40.    VUsrand sets the random number generator seed and VUfrand returns
  41.    a random floating point number in the range [0,1].
  42. */
  43.  
  44. LOCAL LONG 
  45. InitRandom (seed)
  46.      LONG seed;
  47. {
  48.   VUsrand (seed);
  49.   return DV_SUCCESS;
  50. }
  51.  
  52. LOCAL LONG ReadRandom 
  53. V_P_ ((void))
  54. {
  55.   return DV_SUCCESS;
  56. }
  57.  
  58. LOCAL LONG TermRandom 
  59. V_P_ ((void))
  60. {
  61.   return DV_SUCCESS;
  62. }
  63.  
  64. LOCAL LONG 
  65. CharSelectRandom (minval, maxval)
  66.      double *minval;
  67.      double *maxval;
  68. {
  69.   CHAR d;
  70.  
  71.   d = *minval + (*maxval - *minval) * VUfrand ();
  72.   TdsvSetTypedValue (M_dsvcurrent, V_C_TYPE, (ADDRESS) & d, (INT) 0, (INT) 0);
  73.   return DV_SUCCESS;
  74. }
  75.  
  76.  
  77. LOCAL LONG 
  78. ShortSelectRandom (minval, maxval)
  79.      double *minval;
  80.      double *maxval;
  81. {
  82.   SHORT d;
  83.   d = *minval + (*maxval - *minval) * VUfrand ();
  84.   TdsvSetTypedValue (M_dsvcurrent, V_S_TYPE, (ADDRESS) & d, (INT) 0, (INT) 0);
  85.   return DV_SUCCESS;
  86. }
  87.  
  88.  
  89. LOCAL LONG 
  90. LongSelectRandom (minval, maxval)
  91.      double *minval;
  92.      double *maxval;
  93. {
  94.   LONG d;
  95.   d = *minval + (*maxval - *minval) * VUfrand ();
  96.   TdsvSetTypedValue (M_dsvcurrent, V_L_TYPE, (ADDRESS) & d, (INT) 0, (INT) 0);
  97.   return DV_SUCCESS;
  98. }
  99.  
  100.  
  101. LOCAL LONG 
  102. FloatSelectRandom (minval, maxval)
  103.      double *minval;
  104.      double *maxval;
  105. {
  106.   FLOAT d;
  107.   d = *minval + (*maxval - *minval) * VUfrand ();
  108.   TdsvSetTypedValue (M_dsvcurrent, V_F_TYPE, (ADDRESS) & d, (INT) 0, (INT) 0);
  109.   return DV_SUCCESS;
  110. }
  111.  
  112.  
  113. LOCAL LONG 
  114. DoubleSelectRandom (minval, maxval)
  115.      double *minval;
  116.      double *maxval;
  117. {
  118.   DOUBLE d;
  119.   d = *minval + (*maxval - *minval) * VUfrand ();
  120.   TdsvSetTypedValue (M_dsvcurrent, V_D_TYPE, (ADDRESS) & d, (INT) 0, (INT) 0);
  121.   return DV_SUCCESS;
  122. }
  123.  
  124. LOCAL LONG 
  125. MatrixSelectRandom (minval, maxval)
  126.      double *minval;
  127.      double *maxval;
  128. {
  129.   FLOAT s;
  130.   INT j;
  131.   INT rows, cols, num_elements;
  132.  
  133.   TdsvGetSize (M_dsvcurrent, &rows, &cols);
  134.   num_elements = rows * cols;
  135.   for (j = 0; j < num_elements; j++)
  136.     {
  137.       s = VUfrand ();
  138.       s = *minval + (*maxval - *minval) * s;
  139.       TdsvSetTypedValue (M_dsvcurrent, V_F_TYPE, (ADDRESS) & s,
  140.                          (LONG) 0, (LONG) j);
  141.     }
  142.   return DV_SUCCESS;
  143. }
  144.  
  145. V_FDS_FCN_DECL (V_FDS_FCN_OPEN, FD_InitRandom, 
  146.         InitRandom, "Set random # seed")
  147. V_FDS_LONG_ARG_DECL ("seed", 654321)
  148. V_FDS_END_FCN_DECL
  149.  
  150. V_FDS_FCN_DECL (V_FDS_FCN_CLOSE, FD_TermRandom, TermRandom, "Terminate")
  151. V_FDS_END_FCN_DECL
  152.  
  153. V_FDS_FCN_DECL (V_FDS_FCN_READ, FD_ReadRandom, ReadRandom, "Read")
  154. V_FDS_END_FCN_DECL
  155.  
  156. V_FDS_FCN_DECL (V_FDS_FCN_SELECT, FD_CharSelectRandom,
  157.         CharSelectRandom, "Get byte random datum")
  158. V_FDS_DOUBLE_ARG_DECL ("Minimum Value", 0.0)
  159. V_FDS_DOUBLE_ARG_DECL ("Maximum Value", 100.0)
  160. V_FDS_END_FCN_DECL
  161.  
  162. V_FDS_FCN_DECL (V_FDS_FCN_SELECT, FD_ShortSelectRandom,
  163.         ShortSelectRandom, "Get word random datum")
  164. V_FDS_DOUBLE_ARG_DECL ("Minimum Value", 0.0)
  165. V_FDS_DOUBLE_ARG_DECL ("Maximum Value", 100.0)
  166. V_FDS_END_FCN_DECL
  167.  
  168. V_FDS_FCN_DECL (V_FDS_FCN_SELECT, FD_LongSelectRandom, 
  169.         LongSelectRandom, "Get long random datum")
  170. V_FDS_DOUBLE_ARG_DECL ("Minimum Value", 0.0)
  171. V_FDS_DOUBLE_ARG_DECL ("Maximum Value", 100.0)
  172. V_FDS_END_FCN_DECL
  173.  
  174. V_FDS_FCN_DECL (V_FDS_FCN_SELECT, FD_FloatSelectRandom, 
  175.         FloatSelectRandom, "Get float random datum")
  176. V_FDS_DOUBLE_ARG_DECL ("Minimum Value", 0.0)
  177. V_FDS_DOUBLE_ARG_DECL ("Maximum Value", 100.0)
  178. V_FDS_END_FCN_DECL
  179.  
  180. V_FDS_FCN_DECL (V_FDS_FCN_SELECT, FD_DoubleSelectRandom, 
  181.         DoubleSelectRandom, "Get double random datum")
  182. V_FDS_DOUBLE_ARG_DECL ("Minimum Value", 0.0)
  183. V_FDS_DOUBLE_ARG_DECL ("Maximum Value", 100.0)
  184. V_FDS_END_FCN_DECL
  185.  
  186. V_FDS_FCN_DECL (V_FDS_FCN_SELECT, FD_MatrixSelectRandom, 
  187.         MatrixSelectRandom, "Random data for matrix variables")
  188. V_FDS_DOUBLE_ARG_DECL ("Minimum Value", 0.0)
  189. V_FDS_DOUBLE_ARG_DECL ("Maximum Value", 1.0)
  190. V_FDS_END_FCN_DECL
  191.  
  192. V_FDS_START_DECL (FDSrandom)
  193. V_FDS_FCN_DEFINED (FD_InitRandom)
  194. V_FDS_FCN_DEFINED (FD_TermRandom)
  195. V_FDS_FCN_DEFINED (FD_ReadRandom)
  196. V_FDS_FCN_DEFINED (FD_CharSelectRandom)
  197. V_FDS_FCN_DEFINED (FD_ShortSelectRandom)
  198. V_FDS_FCN_DEFINED (FD_LongSelectRandom)
  199. V_FDS_FCN_DEFINED (FD_FloatSelectRandom)
  200. V_FDS_FCN_DEFINED (FD_DoubleSelectRandom)
  201. V_FDS_FCN_DEFINED (FD_MatrixSelectRandom)
  202. V_FDS_END_DECL
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.